 package server.shops;

 import client.MapleCharacter;
 import client.MapleClient;
 import client.inventory.Item;
 import client.inventory.ItemFlag;
 import java.util.ArrayList;
 import java.util.List;
 import server.MapleInventoryManipulator;
 import tools.packet.PlayerShopPacket;

 public class MaplePlayerShop
   extends AbstractPlayerStore
 {
/*  15 */   private final List<String> bannedList = new ArrayList<>();
/*  16 */   private int boughtnumber = 0;

   public MaplePlayerShop(MapleCharacter owner, int itemId, String desc) {
/*  19 */     super(owner, itemId, desc, "", 6);
   }


   public void buy(MapleClient c, int item, short quantity) {
/*  24 */     MaplePlayerShopItem pItem = this.items.get(item);
/*  25 */     if (pItem.bundles > 0) {
/*  26 */       Item newItem = pItem.item.copy();
/*  27 */       newItem.setQuantity((short)(quantity * newItem.getQuantity()));
/*  28 */       short flag = newItem.getFlag();

/*  30 */       if (ItemFlag.可以交换1次.check(flag)) {
/*  31 */         newItem.setFlag((short)(flag - ItemFlag.可以交换1次.getValue()));
/*  32 */       } else if (ItemFlag.宿命剪刀.check(flag)) {
/*  33 */         newItem.setFlag((short)(flag - ItemFlag.宿命剪刀.getValue()));
       }
/*  35 */       long gainmeso = pItem.price * quantity;
/*  36 */       if (c.getPlayer().getMeso() >= gainmeso) {
/*  37 */         if (getMCOwner().getMeso() + gainmeso > 0L && MapleInventoryManipulator.checkSpace(c, newItem.getItemId(), newItem.getQuantity(), newItem.getOwner()) && MapleInventoryManipulator.addFromDrop(c, newItem, false)) {
/*  38 */           pItem.bundles = (short)(pItem.bundles - quantity);
/*  39 */           this.bought.add(new AbstractPlayerStore.BoughtItem(newItem.getItemId(), quantity, gainmeso, c.getPlayer().getName()));
/*  40 */           c.getPlayer().gainMeso(-gainmeso, false);
/*  41 */           getMCOwner().gainMeso(gainmeso, false);
/*  42 */           if (pItem.bundles <= 0) {
/*  43 */             this.boughtnumber++;
/*  44 */             if (this.boughtnumber == this.items.size()) {
/*  45 */               closeShop(true, true);
               return;
             }
           }
         } else {
/*  50 */           c.getPlayer().dropMessage(1, "Your inventory is full.");
         }
       } else {
/*  53 */         c.getPlayer().dropMessage(1, "You do not have enough mesos.");
       }
/*  55 */       getMCOwner().getClient().announce(PlayerShopPacket.shopItemUpdate(this));
     }
   }


   public byte getShopType() {
/*  61 */     return 2;
   }


   public void closeShop(boolean sellout, boolean remove) {
/*  66 */     byte error = (byte)(sellout ? 17 : 3);
/*  67 */     MapleCharacter owner = getMCOwner();
/*  68 */     removeAllVisitors(error, 1);
/*  69 */     getMap().removeMapObject(this);

/*  71 */     for (MaplePlayerShopItem items : getItems()) {
/*  72 */       if (items.bundles > 0) {
/*  73 */         Item newItem = items.item.copy();
/*  74 */         newItem.setQuantity((short)(items.bundles * newItem.getQuantity()));
/*  75 */         if (MapleInventoryManipulator.addFromDrop(owner.getClient(), newItem, false)) {
/*  76 */           items.bundles = 0; continue;
         }
/*  78 */         saveItems();

         break;
       }
     }
/*  83 */     owner.setPlayerShop(null);
/*  84 */     update();
/*  85 */     getMCOwner().getClient().announce(PlayerShopPacket.shopErrorMessage(error, 0));
   }

   public void banPlayer(String name) {
/*  89 */     if (!this.bannedList.contains(name)) {
/*  90 */       this.bannedList.add(name);
     }
/*  92 */     int slot = -1; int i;
/*  93 */     for (i = 0; i < getMaxSize(); i++) {
/*  94 */       MapleCharacter chr = getVisitor(i);
/*  95 */       if (chr != null && chr.getName().equals(name)) {
/*  96 */         slot = i + 1;

         break;
       }
     }
/* 101 */     if (slot != -1) {
/* 102 */       for (i = 0; i < getMaxSize(); i++) {
/* 103 */         MapleCharacter chr = getVisitor(i);
/* 104 */         if (chr != null && chr.getName().equals(name)) {
/* 105 */           chr.send(PlayerShopPacket.shopErrorMessage(5, slot));
/* 106 */           chr.setPlayerShop(null);
/* 107 */           removeVisitor(chr);
         }
       }
     }
   }

   public boolean isBanned(String name) {
/* 114 */     return this.bannedList.contains(name);
   }
 }


/* Location:              C:\PGX\Server.jar!\server\shops\MaplePlayerShop.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */